﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.SalesWeighings
{
    public class WeighTheFatUpdateHandler : IRequestHandler<WeighTheFatUpdateCommond, Resqults>
    {

        private readonly IBateRepository<WeighTheFat> _WeighTheFat;

        public WeighTheFatUpdateHandler(IBateRepository<WeighTheFat> weighTheFat)
        {
            _WeighTheFat = weighTheFat;
        }

        public async Task<Resqults> Handle(WeighTheFatUpdateCommond request, CancellationToken cancellationToken)
        {
            var list = new Resqults() { Code = 0 };


            var query = _WeighTheFat.GetAll().FirstOrDefault(x => x.MyProperty == request.MyProperty);

            if (query != null) {

                query.ScaleId = request.ScaleId;
                query.State = request.State;
                query.BulkSlaughterNo = request.BulkSlaughterNo;
                query.AverageWeight = request.AverageWeight;
                query.NetWeight = request.NetWeight;
                query.ProductCode = request.ProductCode;
                query.Remark = request.Remark;
                query.RepositoryID = request.RepositoryID;
                query.Tare = request.Tare;
                query.WeighTime = request.WeighTime;
                query.WeightNum = request.WeightNum;
            }
           var gh= _WeighTheFat.Update(query);

            if (gh != null)
            {
                list.Code = 0;
            }


            return list;



        }
    }
}
